import React, { Component } from "react";
// Provider 提供数据
// Consumer 消费数据
const { Provider, Consumer } = React.createContext();

class Son extends Component {
  render() {
    return (
      <div>
        <h2>Son</h2>
        <Consumer>
          {
            msg => {
              return <div>{msg}</div>
            }
          }
        </Consumer>
      </div>
    );
  }
}

class Parent extends Component {
  render() {
    return (
      <div>
        <h2>parent</h2>
        <Son></Son>
      </div>
    );
  }
}

export default class App extends Component {
  state = {
    msg: "app组件的数据",
  };
  render() {
    return (
      <div>
        <h1>app</h1>
        <Provider value={this.state.msg}>
          <Parent></Parent>
        </Provider>
      </div>
    );
  }
}
